package com.CampusLife.controller;

import  com.CampusLife.bean.Favorite;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import  com.CampusLife.service.IFavoriteService;
import  com.CampusLife.until.DataTime;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/favorite")
public class FavoriteController {
    @Resource
    private IFavoriteService iFavoriteService;
    //用户查看自己收藏
    @RequestMapping("/user_favorite")
    public  String  user_favorite(HttpSession httpSession,Model model){
        int i=(int)httpSession.getAttribute("id");
        List<Favorite> favorites=iFavoriteService.queryById(i);
        model.addAttribute("admins",favorites);
        return  "/home.jsp";
    }
    @RequestMapping("/add")
    public String addcomment( int p_id, HttpSession httpSession, Model model){
        Favorite favorite=new Favorite();
        favorite.setP_id(p_id);
        int i=(int) httpSession.getAttribute("id");
        favorite.setId(i);

        DataTime dataTime=new DataTime();
        String data=dataTime.gettime();
        favorite.setTime(data);
        iFavoriteService.add(favorite);
        return "";
    }
    @RequestMapping("/delete")
    public  String delete(Integer fid){
        iFavoriteService.delete(fid);
        return "";
    }
}
